#Two string representations

class Point2D:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __str__(self):
        return '({}, {})'.format(self.x, self.y)
        
    def __repr__(self):
        return 'Point2D(x={}, y={})'.format(self.x, self.y)

p = Point2D(42, 69)
str(p)
repr(p)


#Strings for clients with str()
p = Point2D(123, 456)
str(p)

#Using str
print('The circle is centered at {}.'.format(p))

#Using repr
print('The circle is centered at {}.'.format(repr(p)))


#print() uses str()
print(Point2D(123, 456))



#str() defaults to repr()
class Point2D:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __repr__(self):
        return 'Point2D(x={}, y={})'.format(self.x, self.y)

p = Point2D(234, 567)
str(p)
'Point2D(x=234, y=567)'

#The __str__() method is NOT default for repr() 
class Point2D:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __str__(self):
        return '({}, {})'.format(self.x, self.y)

p = Point2D(234, 567)
str(p)
repr(p)


#Printing collections of objects
class Point2D:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __str__(self):
        return '({}, {})'.format(self.x, self.y)
        
    def __repr__(self):
        return 'Point2D(x={}, y={})'.format(self.x, self.y)

l = [Point2D(i, i * 2) for i in range(3)]
str(l)
repr(l)

d = {i: Point2D(i, i * 2) for i in range(3)}
str(d)
repr(d)
